package com.jt.www.job.endorse;

import com.jt.www.biz.order_pc.service.EndorseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;

/**
 * 投保单是否出单定时任务
 */
@Component
@EnableScheduling
public class InsuranceScheduleTask implements SchedulingConfigurer {

    public static final Logger log = LoggerFactory.getLogger(InsuranceScheduleTask.class);
    /**
     * 单个服务器出单查询缓存失效时间 因不同的定时任务决定
     */
    private static final long INSURANCE_TIME_OUT = 120L;
    /**
     * 出单缓存key
     */
    private static final String INSURANCE_LOCK_KEY = "EDU_INSURANCE";
    @Autowired
    private EndorseService endorseService;
    /**
     * 任务开关
     */
    @Value("${jtpf.insurance.open}")
    private int checkOpen;
    /**
     * 任务执行周期
     */
    @Value("${jtpf.insurance.cron}")
    private String cron;

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        if (checkOpen != 1) {
            return;
        }
        Runnable task0 = () -> endorseService.insuranceEffect();
        Trigger trigger0 = triggerContext -> new CronTrigger(cron).nextExecutionTime(triggerContext);
        taskRegistrar.addTriggerTask(task0, trigger0);
    }
}